import {useReducer} from "react";

const NAME = 'NAME'
const NICKNAME = 'NICKNAME'
const INTRODUCTION = 'INTRODUCTION'
const PHONE = 'PHONE'
const EMAIL = 'EMAIL'
const PROVINCE = 'PROVINCE'
const CITY = 'CITY'

const initialState = {
  name: '',
  nickname: '',
  introduction: '',
  phone: '',
  email: '',
  province: '',
  city: '',
}

const reducer = (state, action) => {
  switch (action.type){
    case NAME:
      return {...state, name: action.value}
    case NICKNAME:
      return {...state, nickname: action.value}
    case INTRODUCTION:
      return {...state, introduction: action.value}
    case PHONE:
      return {...state, phone: action.value}
    case EMAIL:
      return {...state, email: action.value}
    case PROVINCE:
      return {...state, province: action.value}
    case CITY:
      return {...state, city: action.value}
    default:
      return state
  }
}
export function createAction(type, value){
  return {type, value}
}
export function useUserInfo() {
  const [userInfo, userInfoDispatch] = useReducer(reducer, initialState)

  return {userInfo, userInfoDispatch}
}